package it.polimi.it.TravelDream.entities;

import it.polimi.it.TravelDream.ejb.eaos.PackageDTO;

import java.io.Serializable;

import javax.persistence.*;


import java.util.Date;
import java.util.Random;


/**
 * The persistent class for the predefined_package database table.
 * 
 */
@Entity
@Table(name="predefined_package")
@NamedQueries({
	@NamedQuery(name=PredefinedPackage.FIND_ALL,
				query="SELECT p FROM PredefinedPackage p" ),

	@NamedQuery(name=PredefinedPackage.DELETE,
				query="DELETE  FROM PredefinedPackage p " )
})


public class PredefinedPackage implements Serializable {
	private static final long serialVersionUID = 1L;
	public static final String FIND_ALL = "PredefinedPackage.findAll";
	public static final String DELETE= "PredefinedPackage.delete";
	

	@Id
	private String idpackage;

	@Temporal(TemporalType.DATE)
	private Date creationdata;

	private int discount;

	private String employeecreator;

	private String idbasicproduct1;

	private String idbasicproduct2;

	private String idbasicproduct3;

	private int totalprice;
	
	private String idbuyer;

	static final String ALPHABET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	
    static Random rnd = new Random(System.currentTimeMillis());
    
    static private final int LENGHT = 4;
    
	//costruttore genera un pacchetto predefinito vuoto con un nuovo ID
	public PredefinedPackage() {
		this.idpackage=generateIDPackage();
	}

	public PredefinedPackage(PackageDTO pack, String employeeCreator){
		this.idpackage  = pack.getIdPackage();
        this.creationdata = pack.getCreationData();
        this.discount = pack.getDiscount();
        this.employeecreator = employeeCreator;
        this.idbasicproduct1 = pack.getIdBasicProduct1();
        this.idbasicproduct2 = pack.getIdBasicProduct2();
        this.idbasicproduct3 = pack.getIdBasicProduct3();
        this.totalprice = pack.getTotalPrice();
        this.idbuyer = 	pack.getIdBuyer();
	}

    private static String generateIDPackage() {
        StringBuilder sb = new StringBuilder(LENGHT);
        for (int i = 0; i < LENGHT; i++) {
            sb.append(ALPHABET.charAt(rnd.nextInt(ALPHABET.length())));
        }
        return sb.toString();
    }

	
	public String getIdpackage() {
		return this.idpackage;
	}

	public void setIdpackage(String idpackage) {
		this.idpackage = idpackage;
	}

	public Date getCreationdata() {
		return this.creationdata;
	}

	public void setCreationdata(Date creationdata) {
		this.creationdata = creationdata;
	}

	public int getDiscount() {
		return this.discount;
	}

	public void setDiscount(int discount) {
		this.discount = discount;
	}

	public String getEmployeecreator() {
		return this.employeecreator;
	}

	public void setEmployeecreator(String employeecreator) {
		this.employeecreator = employeecreator;
	}

	public String getIdbasicproduct1() {
		return this.idbasicproduct1;
	}

	public void setIdbasicproduct1(String idbasicproduct1) {
		this.idbasicproduct1 = idbasicproduct1;
	}

	public String getIdbasicproduct2() {
		return this.idbasicproduct2;
	}

	public void setIdbasicproduct2(String idbasicproduct2) {
		this.idbasicproduct2 = idbasicproduct2;
	}

	public String getIdbasicproduct3() {
		return this.idbasicproduct3;
	}

	public void setIdbasicproduct3(String idbasicproduct3) {
		this.idbasicproduct3 = idbasicproduct3;
	}

	public int getTotalprice() {
		return this.totalprice;
	}

	public void setTotalprice(int totalprice) {
		this.totalprice = totalprice;
	}

	public String getIdbuyer() {
		return idbuyer;
	}

	public void setIdbuyer(String idbuyer) {
		this.idbuyer = idbuyer;
	}
	

}